package com.twu.biblioteca;

public class Movie implements Item {
    private String title;
    private String director;
    private int year;
    private Integer rating;
    private boolean checkedOut;

    public Movie(String title, String director, Integer rating, int year) {
        if(rating != null && (rating <= 0 || rating >= 11)) {
            throw new IllegalArgumentException("Rating must be between 1-10 or unrated");
        }
        this.title = title;
        this.director = director;
        this.rating = rating;
        this.year = year;
    }

    @Override
    public String displayDetails() {
        return title + " | " + director + " | " + (rating == null ? "-" : rating) + " | " + year;
    }

    @Override
    public String displayTitle() {
        return title;
    }

    @Override
    public boolean isCheckedOut() {
        return checkedOut;
    }

    @Override
    public boolean checkout() {
        if(checkedOut) {
            return false;
        }
        checkedOut = true;
        return true;
    }

    @Override
    public boolean returnItem() {
        throw new UnsupportedOperationException();
    }
}